#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN=1050;
int v,n;
int V[MAXN];
int W[MAXN];
int dp[MAXN];
int main(void){
    int t;
    scanf("%d",&t);
    while(t--){
        memset(V,0,sizeof(V));
        memset(W,0,sizeof(W));
        memset(dp,0,sizeof(dp));
        scanf("%d%d",&n,&v);
        for(int i=1;i<=n;i++){
            scanf("%d",&V[i]);
        }
        for(int i=1;i<=n;i++){
            scanf("%d",&W[i]);
        }
        for(int i=1;i<=n;i++){
            for(int j=v;j>=0;j--){
                if(j>=W[i]){
                    dp[j]=max(dp[j],dp[j-W[i]]+V[i]);
                }
            }
        }
        printf("%d\n",dp[v]);
    }
    return 0;
}